'''
Created on Jun 20, 2013

@author: LuciaWilliams
'''
import networkx as nx
import Data_Center
import User
import random


G=nx.Graph()

# add all nodes. no edges yet
for i in range(3):
    u=User.User()
    G.add_node(u)
    print(u)
    d=Data_Center.Data_Center()
    G.add_node(d)
    print(d)
    
print()
# add all edges
for n1 in nx.nodes(G):
    if isinstance(n1, Data_Center.Data_Center):
        for n2 in nx.nodes(G):
            if isinstance(n2, Data_Center.Data_Center) & (n1 is not n2):
                # DCDC, so latency should be somewhere between 25% and 75%
                # of the distance between DCs
                print(n1, n2)
                perct = random.randint(25, 75)/100
                latency = n1.distance(n2)*perct
                print(latency)
                # DCDC so cost is .03
                G.add_edge(n1, n2, {"latency": latency, "cost": .03})
            elif isinstance(n2, User.User):
                # DCUser, so latency should be somewhere between 100% and 150%
                # of the distance between the DC and the User
                perct = random.randint(100, 150)/100
                latency = n1.distance(n2)*perct
                print(n1, n2)
                print(latency)
                # DCUser so cost is .1
                G.add_edge(n1, n2, {"latency": latency, "cost": .1})

# for every node, print its neighbors
print(nx.info(G))
for node in nx.nodes(G):
    print("for %s all neighbors are:" % node)
    it = nx.all_neighbors(G, node)
    while True:
        try: 
            value = next(it)
            print("    %s" % value)
        except StopIteration:
            break
        
# print every node's edge list, including attributes
for node in nx.nodes(G):
    print(node, G[node])

# print a list of edge costs
print(nx.get_edge_attributes(G, "cost").values())
    
# print a list of edge weights
print(nx.get_edge_attributes(G, "latency").values())